package mi.controls.highlight.impl
{
	import mi.controls.highlight.*;
	/**
	 * 语法高亮的CSharp实现
	 * 
	 * @author liushimin 2011-7-7
	 * 
	 */	
	public class CSharpHightLightImpl implements IHightLight  
	{
		/*子类必须实现本方法,获取高亮替换,元素为 { regex:正则 , match:替换 } */
		public function get regexList():Array{
			return _regexList;
		}
		
		/*获取当前高亮实现的别名用于外部调用*/
		public function get alias():String{
			return "CSHARP";
		}
			
		/** 
		 * 关键词 
		 */ 
		private static var keywords:String = "abstract as base bool break byte case catch char checked class const " +
			"continue decimal default delegate do double else enum event explicit extern false finally fixed " +
			"float for foreach goto if implicit in int interface internal is lock long namespace new null " +
			"object operator out override params private protected public readonly ref return sbyte sealed " +
			"short sizeof stackalloc static string struct switch this throw true try typeof uint ulong unchecked " +
			"unsafe ushort using virtual void volatile while"; 
		
		/** 
		 * 组合关键词表达式 
		 */ 
		private static var  KEYWORDS:String = "@interface|\\b(?:" + keywords.split(' ').join('|') + ")\\b"; 
		
		/** 
		 * 匹配 Java 关键词的正则表达式 
		 */ 
		private static var REGEX_KEYWORDS:RegExp = new RegExp(HLConstant.REGEX_UN_LANGUAGE+"|" + "(" + KEYWORDS + ")","g"   
		); 
		
		
		private static var _regexList:Array=[
			/*double Quoted*/
			{
				regex:HLConstant.REGEX_QUOTE_STRING,
				match:function($0:String,$1:String,$2:String,pos:int,all:String):String{
					if($2==""){
						return $1;
					}
					else{
						return $1+"<font color=\"#2a00ff\">"+$2.replace(/(\r)/g,"</font>$&<font color=\"#2a00ff\">")+"</font>"
					}
				}
			},
			//关键字
			{
				regex:REGEX_KEYWORDS,
				match:function($0:String,$1:String,$2:String,pos:int,all:String):String{
					if($2==""){
						return $1;
					}
					else{
						return $1+"<b><font color=\"#7F0055\">"+$2+"</font></b>";
					}
				}
			},
			//字符
			{
				regex:HLConstant.REGEX_QUOTE_CHAR,
				match:function($0:String,$1:String,$2:String,pos:int,all:String):String{
					if($2==""){
						return $1;
					}
					else{
						return $1+"<font color=\"#428BDD\">"+$2.replace(/(\r)/g,"</font>$&<font color=\"#428BDD\">")+"</font>";
					}
				}
			},
			/*Number*/
			{
				regex:HLConstant.REGEX_NUMBER,
				match:function($0:String,$1:String,$2:String,$3:String,pos:int,all:String):String{
					if($2==""){
						return $1;
					}
					else{
						return $1+"<font color=\"#AA3366\">"+$2+"</font>";
					}
				}
			},
			/*MultiLineComment*/
			{
				regex:HLConstant.REGEX_MULTI_COMMENT,
				match:function($0:String,$1:String,$2:String,pos:int,all:String):String{
					if($2==""){
						return $1;
					}
					else{
						return $1+"<font color=\"#3F5FBF\">"+$2.replace(/(\r)/g,"</font>$&<font color=\"#3F5FBF\">")+"</font>";
					}
				}
			},
			/*SingleLineComment*/
			{
				regex:HLConstant.REGEX_SINGLE_COMMENT,
				match:function($0:String,$1:String,$2:String,pos:int,all:String):String{
					if($2==""){
						return $1;
					}
					else{
						return $1+"<font color=\"#008200\">"+$2+"</font>";
					}
				}
			}
		];
			
	}
}